package cn.easybuy.servlet.users;

import cn.easybuy.entity.PageInfo;
import cn.easybuy.entity.User;
import cn.easybuy.service.UserService;
import cn.easybuy.service.impl.UserServiceImpl;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/userDelServlet")
public class UserDelServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            int id =Integer.parseInt(req.getParameter("id")) ;
            User u = new User();
            u.setId(id);
            boolean b = userService.delUsers(u);
            if (b){
                req.setAttribute("msg","删除成功");
               // List<User> list = userService.getListAll();
               // req.setAttribute("userList",list);
                RequestDispatcher disp=req.getRequestDispatcher("/userPageServlet?pageNo=1");
                disp.forward(req,resp);
            }else{
                req.setAttribute("msg","删除失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
